package cn.imvc.app.models;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import cn.imvc.app.entities.StorageOrder;
import cn.imvc.app.repositories.StorageOrderRepository;
import cn.imvc.data.domain.ViewRequest;

@Service
public class StorageOrderModelImpl implements StorageOrderModel {

	@Autowired
	private StorageOrderRepository storageOrderRepository;
	

	public StorageOrder get(int id) {
		return storageOrderRepository.findOne(id);
	}

	public Page<StorageOrder> find(ViewRequest viewRequest) {
		return (Page<StorageOrder>) storageOrderRepository.findAll();
	}

	public StorageOrder save(StorageOrder storageOrder) {
		StorageOrder storageOrder2 = storageOrderRepository.saveAndFlush(storageOrder);
		return storageOrder2;
	}

	public StorageOrder update(StorageOrder newStorageOrder) {
		StorageOrder loadStorageOrder = get(newStorageOrder.getId());
		BeanUtils.copyProperties(newStorageOrder, loadStorageOrder, new String[] { "id" });
		return storageOrderRepository.saveAndFlush(loadStorageOrder);
	}

	public void delete(int id) {
		storageOrderRepository.delete(id);
	}

	public void deleteBatch(int[] ids) {
		for (int id : ids) {
			delete(id);
		}
	}
	
	
}
